import ccclass = cc._decorator.ccclass;
import executionOrder = cc._decorator.executionOrder;
import property = cc._decorator.property;

declare const wx: any

@ccclass()
@executionOrder(-1)
export default class WxDataDispatcher extends cc.Component {
  @property(cc.Node)
  menu: cc.Node = null
  @property(cc.Node)
  beKill: cc.Node = null
  @property(cc.Node)
  gameSurpass: cc.Node = null

  onLoad() {
    wx.onMessage(data => {
      this.node.emit(data.cmd, data)
    })

    this.node.on('enterGame', () => {
      this.menu.active = false
      this.beKill.active = false
      this.gameSurpass.active = false
    })
    this.node.on('beKilled', () => {
      this.menu.active = false
      this.beKill.active = true
      this.gameSurpass.active = false
    })
    this.node.on('enterMenu', () => {
      this.menu.active = true
      this.beKill.active = false
      this.gameSurpass.active = false
    })
  }
}